package com.demo.sse.controller;

import com.demo.sse.model.ServerMessage;
import com.demo.sse.service.SseService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/api/sse")
@CrossOrigin(origins = "*") // Enable CORS for demo purposes
public class SseController {
    private final SseService sseService;

    public SseController(SseService sseService) {
        this.sseService = sseService;
    }

    @GetMapping(path = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ServerMessage> streamEvents() {
        return sseService.getMessageStream();
    }
} 